package com.system.healthproject.model.admin.controller;

import com.system.healthproject.bean.*;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.paramsbean.DiscussSingupParams;
import com.system.healthproject.model.admin.paramsbean.IllDiscussInfo;
import com.system.healthproject.model.admin.paramsbean.IllDiscussParams;
import com.system.healthproject.model.admin.service.IlldiscussService;
import com.system.healthproject.pojo.Doctor;
import com.system.healthproject.pojo.Illdiscuss;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author Xuheng Zhou
 * @date 2020/6/8 18:05
 * @desc
 */
@Controller
@RequestMapping("/admin/Illdiscuss")
@Api(value = "后台病历探讨模块",tags = "后端-病历探讨管理API")
public class IlldiscussController {
    @Autowired
    private IlldiscussService service;


    /**
     * 多条件查询所有病历探讨信息
     * @param selectIllDiscussBean
     * @return
     */

    @ApiOperation(value = "多条件查询病历探讨信息接口(已调试)",notes = "多条件查询病历探讨信息",httpMethod = "post")
    @RequestMapping(value = "/selectIllDiscussWhere",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult<PagesBean<IllDiscussParams>> selectIllDiscussWhere(@RequestBody selectIllDiscussBean selectIllDiscussBean){


        List<IllDiscussParams> list=new ArrayList<>();

        //获取查询的数据
        list=service.selectIllDiscuss(selectIllDiscussBean);
        //获取查询的数据总条数
        Integer count=service.selectIllDiscussCount(selectIllDiscussBean);

        PagesBean pagesBean=new PagesBean();
        pagesBean.setData(list);
        pagesBean.setPageSize(selectIllDiscussBean.getSize());
        //因为查询所有数据的时候，实体类的引用传递，实体类的page值已经改变了，page已经减1，传回前端，就需要加1。
        pagesBean.setNowsPage(selectIllDiscussBean.getPage()+1);
        pagesBean.setDataCount(count);

        return ApiResult.successWithData("查询成功",pagesBean);

    }

    /**
     * 查询病历探讨的详情信息
     * @param illdiscussId
     * @return
     */
    @ApiOperation(value = "查询病历探讨详情信息接口(已调试)",notes = "查询某个病历探讨详情信息",httpMethod = "post")
    @RequestMapping(value = "/selectOneIllDiscuss",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "illdiscussId",value = "病历探讨id",dataType = "String",required = true)
    public ApiResult<IllDiscussInfo> selectOneIllDiscuss(@RequestParam Integer illdiscussId){

        System.out.println(illdiscussId);

        IllDiscussInfo illDiscussInfo = new IllDiscussInfo();
        //获取查询的数据
        illDiscussInfo=service.selectOneIllDiscussById(illdiscussId);

        ApiResult apiResult=new ApiResult();
        if (illDiscussInfo!=null){
            apiResult.setMsg("查询详情成功");
            apiResult.setCode(200);
            apiResult.setData(illDiscussInfo);
        }else {
            apiResult.setMsg("查询详情失败");
            apiResult.setCode(500);
            apiResult.setData(null);
        }

        return apiResult;
    }



    @ApiOperation(value = "病历探讨信息新增接口(已调试)",notes = "新增病历探讨信息",httpMethod = "post")
    @RequestMapping(value = "/insertIllDiscuss",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult insertIllDiscuss(@RequestBody IllDiscussBean illDiscussBean) {

        System.out.println(illDiscussBean);
        //添加病历探讨的信息
        boolean tf=service.addIllDiscuss(illDiscussBean);

        ApiResult apiResult=new ApiResult();
        if(tf){
            apiResult.setMsg("添加成功");
        }
        return apiResult;

    }

    @ApiOperation(value = "病历探讨信息编辑接口(已调试)",notes = "编辑病历探讨信息",httpMethod = "post")
    @RequestMapping(value = "/updateIllDiscuss",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public ApiResult updateIllDiscuss(@RequestBody updateIllDiscussInfo updateIllDiscussInfo) {

        System.out.println(updateIllDiscussInfo);
        boolean tf=service.updateIllDiscuss(updateIllDiscussInfo);
        ApiResult apiResult=new ApiResult();
        if(tf){
            apiResult.setCode(200);
            apiResult.setMsg("编辑成功");
        }else {
            apiResult.setCode(500);
            apiResult.setMsg("编辑失败！");
        }
        return apiResult;
    }

    @ApiOperation(value = "取消病历探讨接口（已调试）",notes = "取消病历探讨",httpMethod = "post")
    @RequestMapping(value = "/cancelIllDiscuss",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "illdiscussId",value = "病历探讨id",dataType = "String",required = true),
            @ApiImplicitParam(name = "illdiscussCancelReason",value = "取消理由",dataType = "String",required = true)
    })
    public ApiResult cancelIllDiscuss(@RequestParam(name = "illdiscussId") Integer illdiscussId,
                                      @RequestParam(name = "illdiscussCancelReason") String illdiscussCancelReason) {

        System.out.println(illdiscussId+"---"+illdiscussCancelReason);
        //取消，先增加取消理由
        //然后再修改状态为 已取消1

        boolean tf=service.cancelIllDiscuss(illdiscussId,illdiscussCancelReason);

        ApiResult apiResult=new ApiResult();
        if (tf){
            apiResult.setCode(200);
            apiResult.setMsg("取消成功");
        }else{
            apiResult.setCode(500);
            apiResult.setMsg("取消失败！请检查是否病历探讨是否选择正确");
        }
        return apiResult;

    }

    @ApiOperation(value = "病历探讨报名查询接口（已调试）",notes = "查询所有的病历探讨报名信息",httpMethod = "post")
    @RequestMapping(value = "/selectDiscussSingup",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "illdiscussId",value = "病历探讨id",dataType = "String",required = true),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "String",required = true),
            @ApiImplicitParam(name = "size",value = "当前页显示的数据条数",dataType = "String",required = true)
    })

    public ApiResult<PagesBean<DiscussSingupParams>> selectDiscussSingup(@RequestParam Integer page ,
                                                                         @RequestParam Integer size,
                                                                         @RequestParam Integer illdiscussId){

        System.out.println(illdiscussId);

        List<DiscussSingupParams> list=new ArrayList<>();
        //根据探讨id查询报名的医生信息
        list=service.selectDiscSingup(illdiscussId,page,size);
        Integer count =service.selectDiscSingupCount(illdiscussId);
        PagesBean<DiscussSingupParams> pagesBean = new PagesBean<>();
        pagesBean.setNowsPage(page);
        pagesBean.setPageSize(size);
        pagesBean.setDataCount(count);
        pagesBean.setData(list);

        return ApiResult.successWithData("成功",pagesBean);
    }


    @ApiOperation(value = "根据医生id查询该医生的病历探讨信息接口(已调试)",notes = "查询医生的病历探讨信息",httpMethod = "post")
    @RequestMapping(value = "/selectIllDiscussByDoctorId",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "doctorId",value = "医生id",dataType = "Integer"),
            @ApiImplicitParam(name = "page",value = "当前页数",dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "页数显示数据条数",dataType = "Integer")
    })
    public ApiResult<PagesBean<selectIllDiscussByDoctorIdBean>> selectIllDiscussByDoctorId(@RequestParam("doctorId") Integer doctorId,
                                                                                           @RequestParam("page") Integer page ,
                                                                                           @RequestParam("size") Integer size){

        List<selectIllDiscussByDoctorIdBean> list=service.selectIllDiscussByDoctorId(doctorId,page,size);
        //获取患教的总条数
        Integer count=service.selectIllDiscussCountByDoctorId(doctorId);
        PagesBean pagesBean=new PagesBean();
        pagesBean.setData(list);
        pagesBean.setPageSize(size);
        pagesBean.setNowsPage(page);
        pagesBean.setDataCount(count);
        return ApiResult.successWithData("查询成功",pagesBean);
    }


    @ApiOperation(value = "删除病历探讨信息接口（已调试）",notes = "删除病历探讨信息",httpMethod = "post")
    @RequestMapping(value = "/deleteIllDiscuss",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    @ApiImplicitParam(name = "illdiscussId",value = "病历探讨id",dataType = "String",required = true)
    public ApiResult deleteIllDiscuss(@RequestParam Integer illdiscussId){

        System.out.println(illdiscussId);

        boolean tf=service.deleteIllDiscussById(illdiscussId);

        ApiResult apiResult=new ApiResult();
        if (tf) {
            apiResult.setMsg("删除病历探讨成功");
            apiResult.setCode(200);
        }else {
            apiResult.setMsg("删除病历探讨失败");
            apiResult.setCode(500);
        }

        return apiResult;
    }
}
